package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

func main() {
	var sliderbar []string
	files, _ := ioutil.ReadDir("./")
	for _, v := range files {
		if !v.IsDir() && strings.LastIndex(v.Name(), ".md") != -1 {
			fmt.Println(v.Name())
			name := strings.Replace(v.Name(), "README", "", 1)
			sliderbar = append(sliderbar, "/"+strings.Replace(name, ".md", "", 1))
		}
	}
	js, _ := json.Marshal(sliderbar)
	jsFile, _ := os.OpenFile("./.vuepress/sidebar.js", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0777)
	defer jsFile.Close()

	fileWriter := bufio.NewWriter(jsFile)
	fileWriter.WriteString("module.exports =" + string(js))
	fileWriter.Flush()
}
